<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="../../vue.js"></script>
    <title>Document</title>
</head>

<body>
    <div id="root">
        <h2>当前n值为:{{n}}</h2>
        <!-- <h2>放大十倍后的n值为:<span v-big-number="n"></span></h2> -->
        <h2>放大十倍后的n值为:<span v-big="n"></span></h2>
        <button @click="n++">点我n加1</button>
        <hr>
        <input type="text" v-fbind:value="n">
    </div>
</body>
<script>
    const vm = new Vue({
        data: {
            n: 1
        },
        // 自定义指令 big何时会被调用？ 1.指令与元素成功绑定时 2.指令所在的模板被解析时
        // directives 中的指令 this 都为window
        // 局部指令
        directives: {
            // 'big-number'(element, binding) {
            //     element.innerText = binding.value * 10
            // },
            big(element, binding) {
                element.innerText = binding.value * 10
            },
            fbind:{
                // 指令与元素成功绑定时
                bind(element,binding){
                    element.value = binding.value
                },
                // 指令所在的元素被插入页面时
                inserted(element, binding){
                    element.focus()
                },
                // 指令所在的模板被重新解析时
                update(element, binding) {
                    console.log('update')
                    element.value = binding.value
                },
            }
        },
    }).$mount('#root')
</script>

</html>